<img id="adImg" width={{.width}} height={{.height}} />
<div id="trackingDiv" style="top:0;left:0;width:0;height:0"></div>

{{range .AD.implTrackingUrls}}
<img src="{{.}}" />
{{end}}

<script type="text/javascript" >
var clkTrackingUrls = {{.AD.clkTrackingUrls}};

function initAd() {
	var clkUrl = {{.clickUrl}};

	var imgUrls = {{.AD.imgUrls}}
	
	var imgDom = document.getElementById("adImg");
	var len = imgUrls.length;
	if (len > 0) {
		imgDom.onclick = function(){
			trackingLoaded(clkTrackingUrls)
			window.location.href = clkUrl;
		}
		imgDom.src = imgUrls[0];
	}
}
function trackingLoaded(trackingUrls) {
	var len = trackingUrls.length;
	var trackingDiv = document.getElementById("trackingDiv");
	for (var i = 0; i < len; i++) {
		var frm = document.createElement("iframe");
		trackingDiv.appendChild(frm);
		frm.width = 0;
		frm.height = 0;
		frm.frameBorder = 0;
		frm.src = trackingUrls[i];
	}
}

window.onload =initAd;
</script>